package com.heima.controller;

import com.heima.pojo.Role;
import com.heima.pojo.dto.UserAddDTO;
import com.heima.pojo.dto.UserPageDTO;
import com.heima.pojo.entity.Business;
import com.heima.pojo.vo.UserPageVO;
import com.heima.result.PageResult;
import com.heima.service.RoleService;
import com.heima.service.UserService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user-service")
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;

    /**
     * 人员分页查询
     *
     * @param dto
     * @return
     */
    @GetMapping("/user/search")
    public PageResult<UserPageVO> page(UserPageDTO dto) {
        PageResult<UserPageVO> vo = userService.page(dto);
        return vo;
    }

    /**
     * 角色列表
     */
    @GetMapping("/role")
    public List<Role> roles() {
        List<Role> role = roleService.list();
        return role;
    }

    /**
     * 新增接口
     */
    //TODO
    @PostMapping("/user")
    public boolean userAdd(@RequestBody UserAddDTO dto) {
        boolean result = roleService.add(dto);
        return result;
    }

    /**
     * 修改人员
     */
    @PutMapping("/user/{userId}")
    public boolean update(@PathVariable Integer userId, @RequestBody UserAddDTO dto) {
        boolean result = userService.update(userId, dto);
        return result;
    }

    /**
     * 删除人员
     */
    @DeleteMapping("user/{userId}")
    public boolean dle(@PathVariable Integer userId) {
        boolean result = userService.del(userId);
        return result;
    }
}
